let newdata = getmyData('disease')
let disdata = []
let count = 0
if (newdata == null) {
    setmyData('disease', disease)
    newdata = getmyData('disease')
}
var fenyedata=newdata
cutdata(newdata, disdata, 3, 5, 2)
showTable(3, disdata)
function mysepcil() {
    let sepc1 = document.querySelectorAll('#mytbody td:nth-of-type(1)')
    let sepc2 = document.querySelectorAll('#mytbody td:last-of-type')
    for (let i = 0; i < sepc1.length; i++) {
        $(sepc1[i]).before(`<td><input type="checkbox" name="" id="${$(sepc1).eq(i).text()}"></td>`)
        //$(sepc1).eq(i).text()  将id与数组的number绑定，方便后面的多选删除
        // console.log($(sepc1).eq(i).text())
    }
    //为数组添加编辑和删除按钮
    for (let o = 0; o < sepc2.length; o++) {
        $(sepc2[o]).after(`<td><a href="">编辑</a><button data-biaoshi='${o}'>删除</button>`)
    }
    //设置删除按钮的样式
    $(`td>button`).css({
        margin: '20px 10px',
        backgroundColor: '#fff',
        color: 'rgba(24, 144, 255, 1)',
        border: 0,
        fontSize: '16px'
    })
    $(`td>a`).css({
        backgroundColor: '#fff',
        color: 'rgba(24, 144, 255, 1)',
        border: 0,
        fontSize: '16px'
    })
    //设置删除事件
    let sepc3 = document.querySelectorAll('#mytbody td:last-of-type')
    $(sepc3).on('click', 'button', function () {
        //获取自定义属性便于单一删除
        let tdxb = parseInt($(this).attr('data-biaoshi'))
        // console.log(sepc3[tdxb]);
        $(sepc3[tdxb]).parent().remove()
        // console.log(123);
        disease.splice(tdxb, 1)
        newdata.splice(tdxb, 1)
        setmyData("disease", newdata)
        console.log(newdata);
        querydata = []
        newdata = getmyData("disease")
        cutdata(newdata, querydata, 3, 5, 2)
        console.log(dangqian)
        showTable(3, querydata)
        
    })
    //将所有sale值为true添加checked事件
    for (let i = 0; i < disease.length; i++) {
        // console.log(JSON.stringify(disease[i].sale))
        if (disease[i].sale == true) {
            $('tbody input').eq(i).prop('checked', true)
        }
    }
}
//为input添加点击事件
$('tbody').on('click', 'input', function () {
    let n = $(this).attr('id')
    for (let i = 0; i < disease.length; i++) {
        // console.log(JSON.stringify(disease[i].sale))
        if (n == disease[i].number) {
            // console.log(n)
            if (disease[i].sale == true) {
                disease[i].sale = false
                count--
            } else {
                disease[i].sale = true
                count++
                break
            }
        }
        // if (disease[i].sale == true) {
        //     disease[i].sale = false
        // } else {
        //     disease[i].sale = true
        //     break
        // }
    } $('#xuanze').text(count)
    // console.log(n)
})
//多选删除按钮功能

for (let i = 0; i < disease.length; i++) {
    if (disease[i].sale == true) {
        count++
    }
}
$('#xuanze').text(count)
$('.queding').click(function () {
    for (let i = 0; i < disease.length; i++) {
        if (disease[i].sale == true) {
            count = 0
            disease.splice(i, 1)
            console.log(disease)
            newdata.splice(i, 1)
            i--
            $('#xuanze').text(count)
        }
    }

    setmyData("disease", newdata)
    console.log(newdata);
    querydata2 = []
    newdata = getmyData("disease")
    cutdata(newdata, querydata2, 3, 5, 2)
    showTable(3, querydata2)
    $("#exampleModal.modal.fade.in").trigger("click")
})

$('#exampleModal').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget) // Button that triggered the modal
    var recipient = button.data('whatever')
    var modal = $(this)
    modal.find('.modal-title').text('你确认要删除这些数据信息吗')
    modal.find('.modal-body input').val(recipient)
})
function reset() {
    $('#selyiji').val('全部')
    $('#selDoname').val('')
    $('#selHoname').val('')
}
function cha() {
    let disdatas=[]
    if ($('#selyiji').val() == '全部') {
        if ($('#selerji').val() != '') {
            let data = disease.filter(item => item.name == $('#selerji').val())
            if (data.length > 0) {
                fenyeData = data
            }
            else {
                $('#exampleModal2').modal('toggle')
            }
        } else if ($('#selerji').val() == '') {
            fenyeData = newdata
        }
    }
    else if ($('#selerji').val() == '') {
        let data = disease.filter(item => item.Dep == $('#selyiji').val())
        fenyeData = data
    }
    else {
        let data = disease.filter(item => item.Dep == $('#selyiji').val() && item.name == $('#selerji').val())
        if (data.length > 0) {
            fenyeData = data
        }
        else {
            // alert('未查询到该科室，请检查是否输入正确！')
            $('#exampleModal2').modal('toggle')
        }
        // fenyeData = data
    }
    cutdata(fenyeData, disdatas, 3, 5, 2)
    console.log(disdatas)
    showTable(3, disdatas)
}